package com.jsbs.iam.auth.service.impl;

import com.alibaba.fastjson.JSON;
import com.jsbs.iam.auth.feign.IamRoleManagerFeign;
import com.jsbs.iam.auth.param.IamQueryUserTypeParam;
import com.jsbs.iam.auth.service.IamUserTypeService;
import com.jsbs.iam.auth.vo.IamUserTypeBaseVo;
import com.jsbs.iam.common.core.dto.Result;
import com.jsbs.iam.common.core.utils.Json;
import com.jsbs.iam.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: IamUserTypeServiceImpl
 * @Author: tenghuawei
 * @Date: 2023/1/6 17:18
 * @Description:
 */

@Slf4j
@Service
public class IamUserTypeServiceImpl implements IamUserTypeService {

    @Autowired
    IamRoleManagerFeign iamRoleManagerFeign;

    /**
     * 功能描述：查询当前登录用户归属租户的用户类型
     * @param
     * @return List
     */
    @Override
    public List<IamUserTypeBaseVo> queryUserTypeList() {
        IamQueryUserTypeParam iamQueryUserTypeParam = new IamQueryUserTypeParam();
        iamQueryUserTypeParam.setUserTypeInfo(StringUtils.EMPTY);
        //查询当前登录用户所属租户的所有用户类型
        Result result = iamRoleManagerFeign.getUserTypeData(iamQueryUserTypeParam.getUserTypeInfo());
        List<IamUserTypeBaseVo> iamUserTypeBaseVos = JSON.parseArray(Json.toJsonString(result.getData()), IamUserTypeBaseVo.class);
//        List<IamUserTypeBaseVo> iamUserTypeBaseVos = Json.parseJsonArray(Json.toJsonString(result.getData()), IamUserTypeBaseVo.class);
        if(CollectionUtils.isEmpty(iamUserTypeBaseVos)){
            log.warn("Route=>IamUserTypeServiceImpl method=>queryUserTypeList 当前登录用户所属租户的用户类型集合为空，入参 :{}", Json.toJsonString(iamQueryUserTypeParam));
            return new ArrayList<IamUserTypeBaseVo>();
        }
        return iamUserTypeBaseVos;
    }
}
